<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动画</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: red;
            border-radius: 50%;
        }
        .actions{
            margin: 0 auto;
        }
        button{
            text-align: center;
            margin: 30px auto;
        }
    </style>
</head>
<body>

    <div class="box"></div>
    <div class="actions">
        <button>开始</button>

    </div>
    
    
</body>
<script>
    let box = document.querySelector('.box');
    let btn = document.querySelector('button');

    let timer;
    let target = {
        x: 500,
        y: 200
    };

    btn.addEventListener('click', e => {
        
        timer = setInterval(() => {
            let x = box.offsetLeft;
            let y = box.offsetTop;

            if(x < target.x){
                box.style.left = x + 1 + 'px';
            }

            if(y < target.y){
                box.style.top = y + 1 + 'px';
            }

            if(x >= target.x && y >= target.y){
                clearInterval(timer);
            }
        }, 5);

    });
</script>
</html>